#pragma once
#include <map>
#include <string>
#include "Windows.h"

class CBaseObject
{
public:
	CBaseObject();
	virtual ~CBaseObject();

public:
	virtual int AddRef();
	virtual int Release();
	virtual int encoding(char * pszBuffer, const int nBufferSize);
	virtual int decoding(const char * pBuffer, const int nBufferSize);


protected:
	inline void lock() { ::EnterCriticalSection(&m_cs); };
	inline void unlock() { ::LeaveCriticalSection(&m_cs); };

protected:
	CRITICAL_SECTION m_cs;
	unsigned int m_nRef;


public:
	static int encodingString(char *pszBuffer, const int nBufferSize, int &pos, const std::string &strTxt);
	static int encodingInt(char *pszBuffer, const int nBufferSize, int &pos, const int value);
	static int encodingFloat(char *pszBuffer, const int nBufferSize, int &pos, const float value);
	static int encodingDouble(char *pszBuffer, const int nBufferSize, int &pos, const double value);
	static int encodingBoolean(char *pszBuffer, const int nBufferSize, int &pos, const bool value);
	static int encodingObject(char *pszBuffer, const int nBufferSize, int &pos, const CBaseObject *pObject);
	static int encodingString2IntMap(char *pszBuffer, const int nBufferSize,
		int &pos, const std::map<std::string, int> &map);
	static int encodingString2FloatMap(char *pszBuffer, int nBufferSize,
		int &pos, const std::map<std::string, float> &map);
	static int encodingString2DoubleMap(char *pszBuffer, int nBufferSize,
		int &pos, const std::map<std::string, double> &map);
	static int encodingString2BooleanMap(char *pszBuffer, int nBufferSize,
		int &pos, const std::map<std::string, bool> &map);
	static int encodingString2StringMap(char *pszBuffer, int nBufferSize,
		int &pos, const std::map<std::string, std::string> &map);
	static int encodingString2ObjectMap(char *pszBuffer, int nBufferSize,
		int &pos, const std::map<std::string, CBaseObject*> &map);
	static int decodingString(const char *pszBuffer, const int nBufferSize, int &pos, std::string &strTxt);
	static int decodingInt(const char *pszBuffer, const int nBufferSize, int &pos, int &value);
	static int decodingFloat(const char *pszBuffer, const int nBufferSize, int &pos, float &value);
	static int decodingDouble(const char *pszBuffer, const int nBufferSize, int &pos, double &value);
	static int decodingBoolean(const char *pszBuffer, const int nBufferSize, int &pos, bool &value);
	static int decodingObject(const char *pszBuffer, const int nBufferSize, int &pos, CBaseObject *& pObject);
	static int decodingString2IntMap(const char *pszBuffer, const int nBufferSize,
		int &pos, std::map<std::string, int> &map);
	static int decodingString2FloatMap(const char *pszBuffer, const int nBufferSize,
		int &pos, std::map<std::string, float> &map);
	static int decodingString2DoubleMap(const char *pszBuffer, const int nBufferSize,
		int &pos, std::map<std::string, double> &map);
	static int decodingString2BooleanMap(const char *pszBuffer, const int nBufferSize,
		int &pos, std::map<std::string, bool> &map);
	static int decodingString2StringMap(const char *pszBuffer, const int nBufferSize,
		int &pos, std::map<std::string, std::string> &map);
	static int decodingString2ObjectMap(const char *pszBuffer, const int nBufferSize,
		int &pos, std::map<std::string, CBaseObject*> &map);
};

